<template>
	<view >
		<!-- 背景图 -->
	
		<view class="wh-w750" style=" position: relative;">
			<image src="https://kshk.91bak.com/imagex/zb/t.jpg" mode="widthFix"
				style=" width: 750rpx;"></image>
		</view>
		<!-- 转盘 -->
		<view class="luck-list"
			style="position: absolute;top: 768rpx;right: 0;left: 72rpx; width: 600rpx;">
			
			<view v-for="(item,index) in AwardList" :key="index">
				<view class="" v-if="index==4">
				<image src="https://kshk.91bak.com/imagex/zb/btnx.png" mode="widthFix" style="width: 170rpx;position: absolute;top: 146rpx;" 	@tap="begin(index)"></image>
						<image src="https://kshk.91bak.com/imagex/zb/03.gif" mode="widthFix" style="width: 100rpx;position: absolute;top: 218rpx;left: 282rpx;" 	@tap="begin(index)"></image>
					<view class="cell-itemx" 
						@tap="begin(index)">
					
					</view>
				</view>
				<view class="" v-else>
					<view class="cell-item" :class="index===sel?'y-b':'w-b'"
						@tap="begin(index)">
						<view class="cell-content"
							:class="index===sel?'y':'w'">
							<image :src="item.image" mode="widthFix" style="width: 60rpx; height: 60rpx;" v-if="item.image"></image>
							<view style="margin-top: 5rpx;">
								<text style="font-size: 21rpx; font-weight: bold;color: #FF333B;">{{item.name}}</text>
							</view>
						</view>
					</view>
				</view>
			
			</view>
		</view>
		
	</view>
</template>

<script>
	export default {
		props: {
			// 背景图
			nImg: String,
			// 列表
			AwardList:{
				type:Array,
				default:[]
			},
			// 中奖索引
			sjNum:{
				type:Number,
				default:0
			},
			number:{
				type:Number,
				default:0
			},
		
		},
		data() {
			return {
				
				sel: '',
				FastNums: 0,
				SlowNums: 0,
				time: 1000,
				LoopStatus: true,
				noClick: true
			}
		},
	
		onLoad() {
	
		},
		methods: {
			// 中奖后的逻辑
			updateMoney(sjNum){
				this.$emit('updateMoney',sjNum)
					
			},
			// 开始抽奖
			begin(index) {
			console.log(this.number,'子')
				if(this.number>0){
					
				
				if (index == 4) {
					if (!this.noClick) {
						uni.showToast({
							title: '请勿频繁点击',
							icon: "none",
							position: 'bottom'
						});
						return
					};
				
					this.noClick = false;
					this.FastNums = 0
					this.SlowNums = 0
					this.time = 200
					this.LoopStatus = true
					this.loop()
				}
			}},
			// 抽奖过程 控制
			loop() {
				let sjNum = this.sjNum
				console.log(sjNum)
				if (!this.sel || this.sel < 9) {
					if (this.sel == 3) {
						this.sel = 0
					} else if (this.sel === '') {
						this.sel = 0
					} else if (this.sel == 2) {
						this.sel = 5
					} else if (this.sel == 5) {
						this.sel = 8
					} else if (this.sel == 8) {
						this.sel = 7
					} else if (this.sel == 7) {
						this.sel = 6
					} else if (this.sel == 6) {
						this.sel = 3
					} else {
						this.sel++
					}
					this.FastNums++
					if (this.FastNums == 4) {
						this.FastNums = 0
						this.time = 50
						this.SlowNums++
					}
					if (this.SlowNums == 8) {
						this.SlowNums = 0
						this.time = 500
						this.FastNums = 5
					}
					if (this.FastNums > 5) {
						if (this.sel == sjNum) {
							this.noClick = true;
							this.LoopStatus = false
							// 成功的逻辑
							this.updateMoney(sjNum)
						}
					}
					if (this.LoopStatus) {
						setTimeout(() => {
							this.loop()
						}, this.time);
					}
				}
			}
		}
	
	}
	
</script>

<style scoped>
    /* 抽奖 */
	.luck-list{
		display: flex;
		align-items: center;
		justify-content: center;
		flex-wrap: wrap;
	}
    .cell-item {
    	width: 170rpx;
    	height: 132rpx;
    	border-radius: 30rpx;
    	margin: 5rpx;
    }
    .cell-itemx{
		width: 170rpx;
		height: 132rpx;
		border-radius: 30rpx;
		margin: 5rpx;
	
		
		
	}
    .cell-content {
    	width: 170rpx;
    	height: 122rpx;
    	border-radius: 30rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding-top: 10rpx;
    }
    
    .w {
    	background-color: #ffffff;
    }
    
    .w-b {
    	background-color: #f8d0c3;
    }
    .y {
    	background-color: #ffffff;
		border: 2px solid #fa9534;
    }

    .y-b {
    	background-color: #fa9534;
    }
	.y-c{
		background-color: #FDC041;
	}
</style>
